package com.example.database;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.util.Log;

public class InsertPlayerDB extends AsyncTask<String, Integer, Long> {

	private OpenDB open;

	public InsertPlayerDB(OpenDB op) {
		open = op;
	}

	@Override
	protected Long doInBackground(String... params) {
		final String name = params[0];
		final String position = params[1];
		final String team = params[2];
		final String rating = params[3];

		SQLiteDatabase db = open.getWritableDatabase();

		ContentValues values = new ContentValues();
		values.put(OpenDB.name, name);
		values.put(OpenDB.position, position);
		values.put(OpenDB.team, team);
		values.put(OpenDB.rating, rating);

		return db.insert(OpenDB.table2, null, values);
	}

	@Override
	protected void onPostExecute(Long result) {
		if (result == -1) {
			Log.e("Insert", "Error while insert player in DB");
		}
	}
}
